home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / printpro / newname.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  15.5 KB  |  491 lines

  1. VERSION 2.00
  2. Begin Form LabelMaker 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Address Book"
  5.    ClientHeight    =   6090
  6.    ClientLeft      =   2100
  7.    ClientTop       =   1680
  8.    ClientWidth     =   6540
  9.    Height          =   6780
  10.    Icon            =   NEWNAME.FRX:0000
  11.    Left            =   2040
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   6090
  16.    ScaleWidth      =   6540
  17.    Top             =   1050
  18.    Width           =   6660
  19.    Begin CommandButton QuitButton 
  20.       Caption         =   "QUIT"
  21.       Height          =   495
  22.       Left            =   4920
  23.       TabIndex        =   25
  24.       Top             =   4560
  25.       Width           =   1335
  26.    End
  27.    Begin ListBox NameList 
  28.       Height          =   2175
  29.       Left            =   240
  30.       Sorted          =   -1  'True
  31.       TabIndex        =   24
  32.       Top             =   3840
  33.       Width           =   4335
  34.    End
  35.    Begin TextBox HomePhone 
  36.       Height          =   300
  37.       Left            =   4080
  38.       TabIndex        =   19
  39.       Top             =   3345
  40.       Width           =   1395
  41.    End
  42.    Begin TextBox FaxPhone 
  43.       Height          =   285
  44.       Left            =   2160
  45.       TabIndex        =   17
  46.       Top             =   3345
  47.       Width           =   1395
  48.    End
  49.    Begin TextBox OfficePhone 
  50.       Height          =   285
  51.       Left            =   240
  52.       TabIndex        =   15
  53.       Top             =   3360
  54.       Width           =   1395
  55.    End
  56.    Begin TextBox ZipCode 
  57.       Height          =   285
  58.       Left            =   3390
  59.       TabIndex        =   13
  60.       Top             =   2565
  61.       Width           =   1215
  62.    End
  63.    Begin TextBox StateName 
  64.       Height          =   285
  65.       Left            =   2715
  66.       TabIndex        =   11
  67.       Top             =   2550
  68.       Width           =   375
  69.    End
  70.    Begin TextBox CityName 
  71.       Height          =   285
  72.       Left            =   255
  73.       TabIndex        =   9
  74.       Top             =   2565
  75.       Width           =   2160
  76.    End
  77.    Begin CommandButton Command1 
  78.       Caption         =   "Clear"
  79.       Height          =   375
  80.       Left            =   4920
  81.       TabIndex        =   26
  82.       Top             =   2160
  83.       Width           =   1335
  84.    End
  85.    Begin TextBox SuiteName 
  86.       Height          =   300
  87.       Left            =   255
  88.       TabIndex        =   7
  89.       Top             =   1815
  90.       Width           =   3300
  91.    End
  92.    Begin CommandButton PrintLabel 
  93.       Caption         =   "Print Label"
  94.       Height          =   375
  95.       Left            =   4920
  96.       TabIndex        =   23
  97.       Top             =   1680
  98.       Width           =   1335
  99.    End
  100.    Begin CommandButton DeleteButton 
  101.       Caption         =   "Delete"
  102.       Height          =   375
  103.       Left            =   4920
  104.       TabIndex        =   22
  105.       Top             =   1200
  106.       Width           =   1335
  107.    End
  108.    Begin TextBox StreetName 
  109.       Height          =   300
  110.       Left            =   255
  111.       TabIndex        =   4
  112.       Top             =   1080
  113.       Width           =   3285
  114.    End
  115.    Begin CommandButton SaveButton 
  116.       Caption         =   "Save"
  117.       Height          =   375
  118.       Left            =   4920
  119.       TabIndex        =   21
  120.       Top             =   720
  121.       Width           =   1335
  122.    End
  123.    Begin TextBox LastName 
  124.       Height          =   330
  125.       Left            =   2520
  126.       TabIndex        =   3
  127.       Top             =   330
  128.       Width           =   2250
  129.    End
  130.    Begin TextBox FirstName 
  131.       Height          =   330
  132.       Left            =   255
  133.       TabIndex        =   2
  134.       Top             =   330
  135.       Width           =   2145
  136.    End
  137.    Begin CommandButton AddButton 
  138.       Caption         =   "Add"
  139.       Default         =   -1  'True
  140.       Height          =   405
  141.       Left            =   4920
  142.       TabIndex        =   20
  143.       Top             =   240
  144.       Width           =   1335
  145.    End
  146.    Begin Label Label8 
  147.       Caption         =   "Home Phone"
  148.       Height          =   210
  149.       Left            =   4080
  150.       TabIndex        =   18
  151.       Top             =   3105
  152.       Width           =   1215
  153.    End
  154.    Begin Label Label7 
  155.       Caption         =   "FAX"
  156.       Height          =   240
  157.       Left            =   2175
  158.       TabIndex        =   16
  159.       Top             =   3105
  160.       Width           =   375
  161.    End
  162.    Begin Label Label6 
  163.       Caption         =   "Office Phone"
  164.       Height          =   255
  165.       Left            =   255
  166.       TabIndex        =   14
  167.       Top             =   3090
  168.       Width           =   1215
  169.    End
  170.    Begin Label Label5 
  171.       Caption         =   "Zip Code"
  172.       Height          =   255
  173.       Left            =   3390
  174.       TabIndex        =   12
  175.       Top             =   2295
  176.       Width           =   855
  177.    End
  178.    Begin Label Label4 
  179.       Caption         =   "State"
  180.       Height          =   225
  181.       Left            =   2670
  182.       TabIndex        =   10
  183.       Top             =   2295
  184.       Width           =   495
  185.    End
  186.    Begin Label Label3 
  187.       Caption         =   "City"
  188.       Height          =   255
  189.       Left            =   270
  190.       TabIndex        =   8
  191.       Top             =   2295
  192.       Width           =   375
  193.    End
  194.    Begin Label Label2 
  195.       Caption         =   "Suite or P.O. Box"
  196.       Height          =   255
  197.       Left            =   240
  198.       TabIndex        =   6
  199.       Top             =   1545
  200.       Width           =   1575
  201.    End
  202.    Begin Label Label1 
  203.       Caption         =   "Street"
  204.       Height          =   255
  205.       Left            =   240
  206.       TabIndex        =   5
  207.       Top             =   825
  208.       Width           =   615
  209.    End
  210.    Begin Label LastLabel 
  211.       Caption         =   "Last Name"
  212.       Height          =   225
  213.       Left            =   2535
  214.       TabIndex        =   1
  215.       Top             =   90
  216.       Width           =   975
  217.    End
  218.    Begin Label FirstLabel 
  219.       Caption         =   "First Name"
  220.       Height          =   225
  221.       Left            =   240
  222.       TabIndex        =   0
  223.       Top             =   90
  224.       Width           =   975
  225.    End
  226.    Begin Menu About 
  227.       Caption         =   "About..."
  228.    End
  229.  Dim Groupvar As GroupRecord
  230. Sub About_Click ()
  231.        
  232.        Line1$ = "            A VeeBee Address Book"
  233.        Line2$ = Chr$(13) + Chr$(10) + "Copyright 
  234.  1991 Knowledge Works, Inc."
  235.        Line3$ = Chr$(13) + Chr$(10) + "                Mark S. Burgess"
  236.        MsgBox Line1$ + Line2$ + Line3$, 64, "About The Program"
  237. End Sub
  238. Sub AddButton_Click ()
  239.   '--------Set the Group Values from Input
  240.      Groupvar.Firstname = Firstname.Text
  241.      Groupvar.LastName = LastName.Text
  242.      Groupvar.StreetName = StreetName.Text
  243.      Groupvar.SuiteName = SuiteName.Text
  244.      Groupvar.CityName = CityName.Text
  245.      Groupvar.StateName = UCase$(StateName.Text)
  246.      Groupvar.ZipCode = ZipCode.Text
  247.      Groupvar.OfficePhone = OfficePhone.Text
  248.      Groupvar.FaxPhone = FaxPhone.Text
  249.      Groupvar.HomePhone = HomePhone.Text
  250.   '--------Calculate where to put it in the file
  251.      LastRecord = LOF(100) \ Len(Groupvar)
  252.      LastRecord = LastRecord + 1
  253.      Groupvar.RecordNum = LastRecord
  254.   '--------Add name to the file and to the list
  255.      Put #100, LastRecord, Groupvar
  256.      New$ = RTrim$(Groupvar.LastName) + ", " + Groupvar.Firstname
  257.      NameList.AddItem New$, LastRecord - 1
  258.   '--------Clear out the list
  259.      Firstname.Text = ""
  260.      LastName.Text = ""
  261.      LastName.Text = ""
  262.      StreetName.Text = ""
  263.      SuiteName.Text = ""
  264.      CityName.Text = ""
  265.      StateName.Text = ""
  266.      ZipCode.Text = ""
  267.      OfficePhone.Text = ""
  268.      FaxPhone.Text = ""
  269.      HomePhone.Text = ""
  270.      Firstname.SetFocus
  271. End Sub
  272. Sub CancelButton_Click ()
  273.     Close
  274.     End
  275. End Sub
  276. Sub CityName_KeyPress (KeyAscii As Integer)
  277.        If Len(RTrim$(CityName.Text)) = 20 Then
  278.           KeyAscii = 0
  279.        End If
  280. End Sub
  281. Sub Command1_Click ()
  282.      Firstname.Text = ""
  283.      LastName.Text = ""
  284.      LastName.Text = ""
  285.      StreetName.Text = ""
  286.      SuiteName.Text = ""
  287.      CityName.Text = ""
  288.      StateName.Text = ""
  289.      ZipCode.Text = ""
  290.      OfficePhone.Text = ""
  291.      FaxPhone.Text = ""
  292.      HomePhone.Text = ""
  293.      Firstname.SetFocus
  294. End Sub
  295. Sub DeleteButton_Click ()
  296.        Dim Item As Integer
  297.        Dim Steps As Integer
  298.        If NameList.ListIndex = 0 Then                       ' Check if cursor in list box pos 1
  299.          Item = 2                                           '   Set item to 2nd File Item
  300.        Else                                                 '   otherwise
  301.          Item = NameList.ListIndex + 2                      '   set item 2 positions away in file
  302.        End If
  303.        LastRecord = LOF(100) \ Len(Groupvar)                ' Get number of records in the file
  304.        NameList.RemoveItem NameList.ListIndex               ' Take out the list box display item
  305.        For Steps = Item To LastRecord                       ' From start to end of file
  306.          Get #100, Item, Groupvar                           '   retrieve next file record by item
  307.          Put #100, Item - 1, Groupvar                       '   place it in deleted record pos
  308.          Item = Item + 1                                    '   look to the next item in line
  309.        Next Steps
  310.        Open "~~NAMES.DAT" For Random As 200 Len = 184       ' Create a temporary holding file
  311.        For Steps = 1 To (LastRecord - 1)                    ' From pos 1 to next to last record
  312.          Get #100, Steps, Groupvar                               '   retrieve the record
  313.          Put #200, Steps, Groupvar                          '   place it into the temp file
  314.        Next Steps
  315.        Close                                                ' Close all files
  316.        Kill "NAMES.DAT"                                     ' Delete the original file
  317.        Name "~~NAMES.DAT" As "NAMES.DAT"                    ' Rename the temp file
  318.        Open "NAMES.DAT" For Random As 100 Len = 184         ' Open it for access
  319.        NameList.SetFocus
  320.        Firstname.SetFocus                                   ' Replace the focus on first field
  321. End Sub
  322. Sub FaxPhone_KeyPress (KeyAscii As Integer)
  323.        If Len(RTrim$(FaxPhone.Text)) = 12 Then
  324.           KeyAscii = 0
  325.        End If
  326. End Sub
  327. Sub FileOpener_Click ()
  328. End Sub
  329. Sub FirstName_KeyPress (KeyAscii As Integer)
  330.        If Len(RTrim$(Firstname.Text)) = 20 Then
  331.           KeyAscii = 0
  332.        End If
  333. End Sub
  334. Sub FirstName_LostFocus ()
  335.        If Len(RTrim$(Firstname.Text)) >= 20 Then
  336.          Firstname.SetFocus
  337.        End If
  338. End Sub
  339. Sub Form_Load ()
  340.      Dim NewIndex As Integer
  341.      NewIndex = 0
  342.      msg$ = "To add someone to the List, type their name into"
  343.      msg$ = msg$ + " the appropriate slots and click on the ADD"
  344.      msg$ = msg$ + " button.  You can retrieve the name by"
  345.      msg$ = msg$ + " clicking on the name in the list."
  346.      MsgBox msg$, 64, "To get you started..."
  347.      Open "NAMES.DAT" For Random As 100 Len = 184
  348.      Do Until EOF(100)
  349.        Get #100, , Groupvar
  350.        Names$ = RTrim$(Groupvar.LastName) + ", " + Groupvar.Firstname
  351.        NameList.AddItem Names$, NewIndex
  352.        NewIndex = NewIndex + 1
  353.      Loop
  354. End Sub
  355. Sub GetPick ()
  356.        Dim Item As Integer
  357.        If NameList.ListIndex = 0 Then
  358.          Item = 1
  359.        Else
  360.          Item = NameList.ListIndex + 1
  361.        End If
  362.        Get #100, Item, Groupvar
  363.        Firstname.Text = Groupvar.Firstname
  364.        LastName.Text = Groupvar.LastName
  365.        StreetName.Text = Groupvar.StreetName
  366.        SuiteName.Text = Groupvar.SuiteName
  367.        CityName.Text = Groupvar.CityName
  368.        StateName.Text = Groupvar.StateName
  369.        ZipCode.Text = Groupvar.ZipCode
  370.        OfficePhone.Text = Groupvar.OfficePhone
  371.        FaxPhone.Text = Groupvar.FaxPhone
  372.        HomePhone.Text = Groupvar.HomePhone
  373. End Sub
  374. Sub HomePhone_KeyPress (KeyAscii As Integer)
  375.        If Len(RTrim$(HomePhone.Text)) = 12 Then
  376.           KeyAscii = 0
  377.        End If
  378. End Sub
  379. Sub LastName_KeyPress (KeyAscii As Integer)
  380.        If Len(RTrim$(LastName.Text)) = 20 Then
  381.           KeyAscii = 0
  382.        End If
  383. End Sub
  384. Sub ListName_GotFocus ()
  385.       Do Until EOF(1)
  386.          Get #1, , Groupvar
  387.          NameList.AddItem RTrim$(Groupvar.Firstname) + " " + Groupvar.LastName
  388.       Loop
  389. End Sub
  390. Sub NameList_Click ()
  391.         GetPick
  392. End Sub
  393. Sub NameList_DblClick ()
  394.         GetPick
  395. End Sub
  396. Sub NameList_KeyDown (KeyCode As Integer, Shift As Integer)
  397.     GetPick
  398. End Sub
  399. Sub NameList_KeyUp (KeyCode As Integer, Shift As Integer)
  400.         GetPick
  401. End Sub
  402. Sub OfficePhone_KeyPress (KeyAscii As Integer)
  403.        If Len(RTrim$(OfficePhone.Text)) = 12 Then
  404.           KeyAscii = 0
  405.        End If
  406. End Sub
  407. Sub PrintLabel_Click ()
  408.         If Len(RTrim$(Firstname.Text)) = 0 Then
  409.              MsgBox "No Name Selected to Print", 16, "Printing Status"
  410.              Exit Sub
  411.         End If
  412.         Names$ = RTrim$(Groupvar.Firstname) + " " + Groupvar.LastName
  413.         PrintMsg = "Printing a label for " + Names$ + ", Please Wait..."
  414.         Load PrintProcess
  415.         If MsgBoxMsg = 2 Then
  416.           Unload PrintProcess
  417.           Exit Sub
  418.         End If
  419.         Printer.FontBold = -1
  420.         Get #100, NameList.ListIndex + 1, Groupvar
  421.         Open "\DEV\LPT1" For Output As #2
  422.         
  423.         Print #2, Names$
  424.         
  425.         Print #2, Groupvar.StreetName
  426.         If Len(RTrim$(Groupvar.SuiteName)) > 0 Then
  427.           Print #2, Groupvar.SuiteName
  428.           ExtraLine$ = "Yes"
  429.         End If
  430.         
  431.         City$ = RTrim$(Groupvar.CityName) + ", " + Groupvar.StateName + " " + Groupvar.ZipCode
  432.         Print #2, City$
  433.         
  434.         If ExtraLine$ <> "Yes" Then
  435.           Print #2, " "
  436.         End If
  437.         
  438.         Do Until Count% = 2
  439.           Count% = Count% + 1
  440.           Print #2, " "
  441.         Loop
  442.         Count% = 0
  443.         ExtraLine$ = " "
  444.         Unload PrintProcess
  445.         Close #2
  446.         Firstname.SetFocus
  447. End Sub
  448. Sub QuitButton_Click ()
  449.        Close
  450.        End
  451. End Sub
  452. Sub SaveButton_Click ()
  453.   '--------Set the Group Values from Input
  454.      Groupvar.Firstname = Firstname.Text
  455.      Groupvar.LastName = LastName.Text
  456.      Groupvar.StreetName = StreetName.Text
  457.      Groupvar.SuiteName = SuiteName.Text
  458.      Groupvar.CityName = CityName.Text
  459.      Groupvar.StateName = UCase$(StateName.Text)
  460.      Groupvar.ZipCode = ZipCode.Text
  461.      Groupvar.OfficePhone = OfficePhone.Text
  462.      Groupvar.FaxPhone = FaxPhone.Text
  463.      Groupvar.HomePhone = HomePhone.Text
  464.   '--------Save the values back to the file
  465.      Put #100, Groupvar.RecordNum, Groupvar
  466.      NameList.RemoveItem NameList.ListIndex
  467.      Names$ = RTrim$(Groupvar.LastName) + ", " + Groupvar.Firstname
  468.      NameList.AddItem Names$, Groupvar.RecordNum - 1
  469.      Firstname.SetFocus
  470. End Sub
  471. Sub StateName_KeyPress (KeyAscii As Integer)
  472.        If Len(RTrim$(StateName.Text)) = 2 Then
  473.           KeyAscii = 0
  474.        End If
  475. End Sub
  476. Sub StreetName_KeyPress (KeyAscii As Integer)
  477.        If Len(RTrim$(StreetName.Text)) = 30 Then
  478.           KeyAscii = 0
  479.        End If
  480. End Sub
  481. Sub SuiteName_KeyPress (KeyAscii As Integer)
  482.        If Len(RTrim$(SuiteName.Text)) = 30 Then
  483.           KeyAscii = 0
  484.        End If
  485. End Sub
  486. Sub ZipCode_KeyPress (KeyAscii As Integer)
  487.        If Len(RTrim$(ZipCode.Text)) = 12 Then
  488.           KeyAscii = 0
  489.        End If
  490. End Sub
  491.